package com.mzj.saas.mservice.smartlock.service.luoke;

import com.alibaba.fastjson.JSONObject;
import com.mzj.saas.mservice.smartlock.vo.luoke.LuoKeCallBack;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.Map;

/**
 * @Author panda
 * @Date 2024/1/26
 **/
@Slf4j
@Service
public class SmartLockLkCallBackService {

    @Autowired
    private SmartLockLkEventHandleService smartLockLkEventHandleService;

    public Map<String, Object> callBack(LuoKeCallBack luoKeCallBack) {
        log.info("络克锁回调数据：{}", JSONObject.toJSONString(luoKeCallBack));
        switch (luoKeCallBack.getCode()) {
            case "open_logs"://开门日志推送
                return smartLockLkEventHandleService.lockOpenLog(luoKeCallBack.getMessage());
            case "power_logs"://取电日志推送
                return new HashMap<String, Object>() {
                    {
                        put("code", 200);
                        put("message", "success");
                    }
                };
            case "lock_state"://门锁状态变化推送
                return smartLockLkEventHandleService.lockStateLog(luoKeCallBack.getMessage());
            case "gateway_state"://网关状态变化推送
                return new HashMap<String, Object>() {
                    {
                        put("code", 200);
                        put("message", "success");
                    }
                };
            case "alram_logs"://警报日志推送
                return smartLockLkEventHandleService.lockWarnLog(luoKeCallBack.getMessage());
        }
        return new HashMap<String, Object>() {
            {
                put("code", 500);
                put("message", "日志类型异常");
            }
        };
    }
}
